﻿using System.Threading.Tasks;
using FytSoa.Common;
using FytSoa.Core.Model.Cms;
using FytSoa.Service.DtoModel;
using FytSoa.Service.Interfaces;
using FytSoa.Service.Extensions;
using SqlSugar;
namespace FytSoa.Service.Implements
{
    /*!
    * 文件名称：CmsComment服务接口实现
    * 版权所有：北京飞易腾科技有限公司
    * 企业官网：http://www.feiyit.com
    */
    public class CmsCommentService : BaseServer<CmsComment>, ICmsCommentService
    {
        //查询评论列表带用户信息
        public async Task<ApiResult<Page<AppCommonDto>>> GetPageCommon(PageParm param)
        {
            var res=new ApiResult<Page<AppCommonDto>>(){statusCode=(int)ApiEnum.Error};
            try
            {
                res.data=await Db.Queryable<CmsComment,Core.Model.Member.Member>((c,m)=>new JoinQueryInfos(
                    JoinType.Inner,c.UserId==m.Guid
                ))
                .Where((c,m)=>c.Audit && c.Option==param.types && c.ColumnId==param.guid)
                .OrderBy((c,m)=>c.AddDate,OrderByType.Desc)
                .Select((c,m)=>new AppCommonDto(){
                    Guid=c.Guid,
                    ColumnId=c.ColumnId,
                    UserId=c.UserId,
                    UserName=c.UserName,
                    HeadPic=m.HeadPic,
                    Summary=c.Summary,
                    AddDate=c.AddDate
                }).ToPageAsync(param.page,param.limit);
                res.statusCode=(int)ApiEnum.Status;
            }
            catch (System.Exception ex)
            {
                res.message=ex.Message;
            }
            return res;
        }
    }
}